home *** CD-ROM | disk | FTP | other *** search
/ Delphi Magazine Collection 2001 / Delphi Magazine Collection 20001 (2001).iso / DISKS / Issue46 / Clinic / AutomationServer1ClassU.pas < prev    next >
Encoding:
Pascal/Delphi Source File  |  1999-03-12  |  1.1 KB  |  50 lines

  1. unit AutomationServer1ClassU;
  2.  
  3. interface
  4.  
  5. uses
  6.   ComObj, ActiveX, AutomationServer1_TLB;
  7.  
  8. type
  9.   TClock = class(TAutoObject, IClock)
  10.   private
  11.     RegistrationCookie: Integer;
  12.   protected
  13.     function Get_DateAndTime: TDateTime; safecall;
  14.   public
  15.     procedure Initialize; override;
  16.     destructor Destroy; override;
  17.   end;
  18.  
  19. implementation
  20.  
  21. uses
  22.   ComServ, SysUtils, Forms, Windows;
  23.  
  24. procedure TClock.Initialize;
  25. begin
  26.   inherited;
  27.   OleCheck(RegisterActiveObject(Self as IUnknown, Class_Clock, 
  28.       ActiveObject_Weak, RegistrationCookie));
  29.   Application.MessageBox('COM object starting', 'Information',
  30.     MB_OK or MB_ICONEXCLAMATION);
  31. end;
  32.  
  33. destructor TClock.Destroy;
  34. begin
  35.   Application.MessageBox('COM object ending', 'Information',
  36.     MB_OK or MB_ICONEXCLAMATION);
  37.   OleCheck(RevokeActiveObject(RegistrationCookie, nil));
  38.   inherited
  39. end;
  40.  
  41. function TClock.Get_DateAndTime: TDateTime;
  42. begin
  43.   Result := Now
  44. end;
  45.  
  46. initialization
  47.   TAutoObjectFactory.Create(ComServer, TClock, Class_Clock,
  48.     ciSingleInstance, tmApartment);
  49. end.
  50.